package com.kucai.yifaqapp.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.kucai.yifaqapp.R;
import com.kucai.yifaqapp.dagger.component.activity.DaggerEditActivityComponent;
import com.kucai.yifaqapp.dagger.module.activity.EditActivityModule;
import com.kucai.yifaqapp.global.Info;
import com.kucai.yifaqapp.model.network.entity.res.ResIdearlists;
import com.kucai.yifaqapp.presenter.activity.EditActivityPesenter;
import com.kucai.yifaqapp.ui.view.EditActivityView;

public class EditActivity extends BaseActivity<EditActivityPesenter> implements EditActivityView {

    LinearLayout skinbg;
    TextView titleLeftTv;
    TextView headerTitle;
    TextView idertitle;
    EditText idereditetext;
    Button idearbt;
    TextView contenttitle;
    TextView contentcenter;
    TextView contenttime;
    LinearLayout contentitem;
    private String type;
    private String content;
    private String Idearrd;
    LinearLayout goback;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        skinbg = findViewById(R.id.skinbg);
        titleLeftTv = findViewById(R.id.title_left_tv);
        headerTitle = findViewById(R.id.headerTitle);
        idertitle = findViewById(R.id.idertitle);
        idereditetext = findViewById(R.id.idereditetext);
        idearbt = findViewById(R.id.idearbt);
        contenttitle = findViewById(R.id.contenttitle);
        contentcenter = findViewById(R.id.contentcenter);
        contenttime = findViewById(R.id.contenttime);
        contentitem = findViewById(R.id.contentitem);
        type = getIntent().getStringExtra("type");
        Idearrd = getIntent().getStringExtra("Idearrd");

        if (!TextUtils.isEmpty(Idearrd)) {
            headerTitle.setText("反馈记录");
            idertitle.setVisibility(View.GONE);
            mPresenter.getidearlists(Info.user.token, Idearrd);
        } else {
            if (type.equals("4")) {
                headerTitle.setText("建议反馈");
                idertitle.setText("反馈类型:提交建议");
                idereditetext.setHint("请输入您要反馈的内容");
                contentitem.setVisibility(View.GONE);

            } else if (type.equals("5")) {
                headerTitle.setText("建议反馈");
                idertitle.setText("反馈类型:我要投诉");
                contentitem.setVisibility(View.GONE);
                idereditetext.setHint("请输入您要投诉的内容");
            }
        }
        idearbt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                content = idereditetext.getText().toString().trim();
                if (TextUtils.isEmpty(content)) {
                    Toast.makeText(EditActivity.this, "您未输入任何内容", Toast.LENGTH_SHORT).show();
                } else {
                    mPresenter.putidear(Info.user.token, type, content);
                }
            }
        });
        goback = findViewById(R.id.goback);
        goback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected int setContentView() {
        return R.layout.activity_edit_activty;
    }

    @Override
    protected void ChangeSkin() {
        switch (SkinId) {
            case 17771:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
                break;
            case 17772:
                skinbg.setBackgroundResource(R.mipmap.skin_bg2);
                break;
            case 17773:
                skinbg.setBackgroundResource(R.mipmap.skin_bg3);
                break;
            default:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
        }
    }

    @Override
    protected void initDagger() {
        DaggerEditActivityComponent.builder()
                .editActivityModule(new EditActivityModule(this))
                .build().inject(this);
    }

    @Override
    public void getIdear(ResIdearlists resIdearlists) {
        contenttitle.setText("类型:" + resIdearlists.data.list.get(0).typeName);
        contentcenter.setText(resIdearlists.data.list.get(0).content);
        contenttime.setText(resIdearlists.data.list.get(0).created_at);
    }
}
